package com.demo.common.config;

import com.demo.common.logger.DemoFeignLogger;
import feign.Feign;
import feign.Logger;
import feign.hystrix.HystrixFeign;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

/**
 * Feign 配置类
 *
 * @author YT
 * @date 2019/4/28
 */
@Configurable
public class DemoFeignConfiguration {

    /**
     * 自定义 Feign 客户端连接
     * 使用 HystrixFeign.builder() 创建 HystrixFeign 作为 Feign 客户端
     *
     * @return
     */
    @Bean
    public Feign.Builder client(){
        return HystrixFeign.builder().client(new DemoFeignClient());
    }

    /**
     * 自定义 Logger 配置
     * @return
     */
    @Bean
    public Logger DemoFeignLogger(){
        return new DemoFeignLogger();
    }

    /**
     * 配置 Feign 日志打印等级
     *
     * @return
     */
    @Bean
    public Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }
}
